package www.wxwnb.clerk.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;
import www.wxwnb.clerk.R;
import www.wxwnb.clerk.base.BaseActivity;
import www.wxwnb.clerk.bean.AlreadyCheckBean;
import www.wxwnb.clerk.bean.QueryBean;
import www.wxwnb.clerk.ui.api.ApiServer;
import www.wxwnb.clerk.ui.api.MyRetrofit;
import www.wxwnb.clerk.utils.UrlConnect;

import static android.R.id.list;
import static cn.jpush.android.api.JPushInterface.a.i;

/**
 * Created by lenovo on 2017/9/13.
 */
public class ContentActivity extends BaseActivity {
    private TextView txt_name_con;
    private TextView txt_time_con;
    private ImageView iv_ying_img;
    private ImageView iv_other_img;
    private AlreadyCheckBean.DataBean.PageRecordsBean bean;
    private String name;
    private String time;
    private String iml;
    private String imo;
    private TextView txt_user_con;
    private TextView txt_address;
    private TextView txt_business;
    private TextView txt_business1;
    private TextView txt_type;
    private TextView txt_phone;
    private TextView txt_money;
    private LinearLayout linear_zhuan;
    private ImageView zhuan_im;
    private TextView open;
    private ArrayList<String> list_txt=null;
    private ArrayList<Integer> list_type;
    private int index=0;
    private TextView unCheck;
    private View view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.content_layout);

        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        time = intent.getStringExtra("time");
        iml = intent.getStringExtra("iml");
        imo = intent.getStringExtra("imo");
        String user = intent.getStringExtra("user");
        int money = intent.getIntExtra("money", -1);
        String phone = intent.getStringExtra("phone");
        String address = intent.getStringExtra("address");
        int type = intent.getIntExtra("type",-1);
        int bus = intent.getIntExtra("bus", -1);
        String imz=intent.getStringExtra("imz");
        String remark = intent.getStringExtra("remark");

        Log.i("nnnnnnnn",name+time+iml+imo+"..."+bus);
        TextView title=  (TextView) findViewById(R.id.open_include);
        title.setText("开户详情");
        findViewById(R.id.im_back_include).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        getBusinessDatas(bus);

        txt_name_con = (TextView) findViewById(R.id.txt_name_con);
        txt_time_con = (TextView) findViewById(R.id.txt_time_con);
        iv_ying_img = (ImageView) findViewById(R.id.iv_ying_img);
        iv_other_img = (ImageView) findViewById(R.id.iv_other_img);
        txt_user_con = (TextView) findViewById(R.id.txt_un_con);
        txt_address = (TextView) findViewById(R.id.txt_address_con);
        txt_business = (TextView) findViewById(R.id.txt_bus_con);
        txt_type = (TextView) findViewById(R.id.txt_type_con);
        txt_phone = (TextView) findViewById(R.id.txt_phone_con);
        txt_money = (TextView) findViewById(R.id.txt_money_con);
        view = findViewById(R.id.view_con);
        unCheck = (TextView) findViewById(R.id.uncheck_con);
        //转账记录
        linear_zhuan = (LinearLayout) findViewById(R.id.liean_zhuan);
        zhuan_im = (ImageView) findViewById(R.id.iv_zhuan_img);
        for (int i = 0; i <list_txt.size() ; i++) {
            Log.e("ContentActivity",list_txt.get(i)+""+list_txt.size());

        }
        if(remark!=null){
            view.setVisibility(View.VISIBLE);
            unCheck.setVisibility(View.VISIBLE);
            unCheck.setText("未通过原因: "+remark);
        }
        if(type==1){
            txt_type.setText("商家类型: 运营商家");
        }else if(type==2){
            txt_type.setText("商家类型: 一星商家");
        }else if(type==3){
            txt_type.setText("商家类型: 二星商家");
        }else if(type==4){
            txt_type.setText("商家类型: 三星商家");
        }else if(type==5){
            txt_type.setText("商家类型: 预存商家");
        }else if(type==0){
            txt_type.setText("商家类型: 普通商家");
        }
        txt_name_con.setText("登录名："+name);
        txt_user_con.setText("用户名: "+user);
        txt_address.setText("地址: "+address);

        txt_phone.setText("手机号: "+phone);
        txt_money.setText("开户金额: "+money);
        txt_time_con.setText("创建日期："+time);
        if(imz!=null){
            linear_zhuan.setVisibility(View.VISIBLE);
            Glide.with(ContentActivity.this).load(UrlConnect.licenseImage+imz).into(zhuan_im);
        }
        Glide.with(ContentActivity.this).load(UrlConnect.licenseImage+iml).into(iv_ying_img);
        Glide.with(ContentActivity.this).load(UrlConnect.licenseImage+imo).into(iv_other_img);

    }

    @Override
    protected void initView() {

    }

    @Override
    public void initListener() {
    }

    @Override
    public void initData() {

    }

    @Override
    public void processClick(View v) {

    }
    private void getBusinessDatas(final int bus){
        list_txt=new ArrayList<>();
        list_txt.add("万能保");
        list_type=new ArrayList<>();
        list_type.add(0);
        Flowable<QueryBean> flowable = MyRetrofit.getIntence().getRetrofit(UrlConnect.BASE_URL).create(ApiServer.class).queryBusiness();
        flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<QueryBean>() {
                    @Override
                    public void onNext(QueryBean queryBean) {
                        if(queryBean.getReturnCode()==1){
                            List<QueryBean.DataBean> list = queryBean.getData();
                            for (int i=0;i<list.size();i++){
                                int id = list.get(i).getId();
                                String loginName = list.get(i).getLoginName();
                                list_txt.add(loginName);
                                list_type.add(id);
                                Log.i("zzzzzzzzzz",list.get(i).getId()+"");
                            }
                            for (int i = 0; i <list_type.size() ; i++) {
                                if(bus==list_type.get(i)){
                                  txt_business.setText("上级商家: "+list_txt.get(i));
                                  return;
                                }
                            }
                        }
                    }
                    @Override
                    public void onError(Throwable t) {
                        Toast.makeText(ContentActivity.this, "网络异常，请稍后再试", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
